package com.peanut.baby.mvp.follow;

import android.content.Context;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.peanut.baby.InitManager;
import com.peanut.baby.R;
import com.peanut.baby.model.User;
import com.peanut.devlibrary.imageloader.ImageLoader;
import com.peanut.devlibrary.widget.pullrecycle.BaseRecyclerAdapter;
import com.peanut.devlibrary.widget.pullrecycle.BaseViewHolder;

import java.util.List;

/**
 * Created by anonymouslystudio on 2017/8/7.
 */

public class FollowFansRecyclerAdapter extends BaseRecyclerAdapter<User>{
    private OnChangeFollowStatusListener listener;

    public FollowFansRecyclerAdapter(Context context, List<User> data) {
        super(context, data);
    }

    public void setOnFollowStatusChangeListener(OnChangeFollowStatusListener lis){
        this.listener = lis;
    }

    @Override
    protected void convert(BaseViewHolder holder, User item, int position) {
        super.convert(holder, item, position);
        View area = holder.getView(R.id.follow_fans_area);
        if(position == 0){
            area.setVisibility(View.VISIBLE);
        }else{
            area.setVisibility(View.GONE);
        }
    }

    @Override
    protected void convert(BaseViewHolder holder, final User item) {
        ImageView   avatar = holder.getView(R.id.follow_fans_avatar);
        TextView    nick = holder.getView(R.id.follow_fans_nick);
        TextView    desc = holder.getView(R.id.follow_fans_desc);
        CheckBox    follow = holder.getView(R.id.follow_fans_follow);

        ImageLoader.getInstance().loadImageView(mContext,item.avatar,avatar);
        nick.setText(item.nickname);
        desc.setText("关注 "+item.concernCount+"  |  粉丝 "+item.fansCount);
        follow.setChecked(item.isConcerned == 1);
        follow.setText(item.isConcerned == 1? "已关注":"关注");

        if(InitManager.getInstance().getUserId().equals(item.userId)){
            follow.setVisibility(View.GONE);
        }else{
            follow.setVisibility(View.VISIBLE);
        }

        follow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener != null){
                    listener.onChangeFollowStatus(item);
                }
            }
        });

        avatar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener != null){
                    listener.onAvatarClickListener(item);
                }
            }
        });

    }

    @Override
    protected int getLayoutId() {
        return R.layout.layout_item_follow_fans;
    }

    public interface OnChangeFollowStatusListener{
        void onChangeFollowStatus(User user);
        void onAvatarClickListener(User user);
    }
}
